import json

from flask import current_app
from ronglian_sms_sdk import SmsSDK
class SmsTool:
    sdk=None

    def __init__(self):
        accid=current_app.config.get('RONGLIAN_ACCID')
        accToken=current_app.config.get('RONGLIAN_ACCTOKEN')
        appid=current_app.config.get('RONGLIAN_APPID')
        self.sdk=SmsSDK(accid,accToken,appid)
    def send_code(self,mobile,code):
        tid=current_app.config.get('RONGLIAN_TID')
        time = current_app.config.get('SMS_TIME')
        datas=(code,time)
        resp=self.sdk.sendMessage(tid,mobile,datas)
        res=json.loads(resp)
        if res['statusCode']=='000000' or res['statusCode']=='112310':
            return True
        else:
            return False


